"use strict";

import Ajax from "../libs/ajax";
import Constant from "../libs/constants";

export default {
    get_meeting_config() {
        return Ajax.ajax({
            url: Constant.URL_GET_MEETING_AUTH,
            method: 'get'
        }).then((res) => res.data);
    },
    set_meeting_config(data) {
        return Ajax.ajax({
            url: Constant.URL_SET_MEETING_AUTH,
            method: 'post',
            data: {
                type: 8,
                value: data
            }
        }).then(res => res.data)
    },
    /**
     * 
     * data.type png|jpg
     * data.data base64 code
     */
    query(page_num, page_size, meet_name) {
        if (page_num === undefined || page_size === undefined) {
            return new Promise((resolve, reject) => {
                resolve({ code: 2011, msg: "陌生人查询参数缺失" });
            });
        }
        let suffix = '?page_num=' + page_num + '&page_size=' + page_size;
        if (meet_name) {
            suffix = suffix + '&meet_name=' + meet_name;
        }
        return Ajax.ajax({
            url: Constant.URL_MEETING_QUERY + suffix,
            method: 'get'
        }).then(res => res.data)
    },
    add(params) {
        return Ajax.ajax({
            url: Constant.URL_MEETING_CREATE,
            method: 'post',
            data: params
        }).then(res => res.data); s
    },
    update(params) {
        return Ajax.ajax({
            url: Constant.URL_MEETING_UPDATE,
            method: 'post',
            data: params
        }).then(res => res.data);
    },
    delete(meet_id) {
        return Ajax.ajax({
            url: Constant.URL_MEETING_DELETE,
            method: 'post',
            data: {
                meet_id: meet_id
            }
        }).then(res => res.data);
    },
    query_user(page_num, page_size, meet_id, meet_name) {
        return Ajax.ajax({
            url: Constant.URL_MEETING_QUERY_USER + "?page_num=" +
                page_num + '&page_size=' + page_size + '&meet_id=' +
                meet_id + '&meet_name=' + meet_name,
            method: 'get'
        }).then(res => res.data);
    },
    query_invite() {
        return Ajax.ajax({
            url: Constant.URL_MEETING_QUERY_INVITE,
            method: 'get'
        }).then(res => res.data);
    },
    create_invite(name, meet_id, validate_to) {
        return Ajax.ajax({
            url: Constant.URL_MEETING_CREATE_INVITE,
            method: 'post',
            data: {
                invite_name: name,
                meet_id: meet_id,
                validate_to: validate_to
            }
        }).then((res) => res.data);
    },
    remove_user(user_id, meet_id) {
        return Ajax.ajax({
            url: Constant.URL_MEETING_REMOVE_USER,
            method: 'post',
            data: {
                user_id: user_id,
                meet_id: meet_id
            }
        }).then((res) => { res.data });
    },
    add_user(user_id, meet_id) {
        return Ajax.ajax({
            url: Constant.URL_MEETING_ADD_USER,
            method: 'post',
            data: {
                user_id,
                meet_id
            }
        }).then((res) => { res.data });
    }
}
